package com.base.common.converter;

import java.text.DecimalFormat;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.operamasks.faces.annotation.Convert;
import org.operamasks.faces.annotation.DefineConverter;
import org.operamasks.faces.annotation.Format;

@DefineConverter(id = "standardMoneyFormatter")
public class StandardMoneyConverter implements Converter {
	@Format
	public String format(Object value) {
		if (value == null) {
			return "";
		} else {
			DecimalFormat df = new DecimalFormat("0.00");
			return df.format(value);
		}
	}

	@Convert
	public Object convert(String value) {
		return null;
	}

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
		if (value == null) {
			return "";
		} else {
			DecimalFormat df = new DecimalFormat("0.00");
			return df.format(value);
		}
	}
}
